1466F - Euclid's nightmare - CodeForces Solution


bitmasks dfs and similar dsu graphs greedy math sortings *2100

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define B break
#define C continue
#define R return
#define mid ((l+r)/2)
#define left (2*idx)
#define right (2*idx+1)

using namespace std;

const ll Mod=1e9+7 , N = 500500 , inf=1e18;
ll n , m , k , q , x , y , z , a[N] , vis[N] , special[N] , done[N] , ans[N] , sum=0 , mn=inf , mx=0 ;

ll par[N],sz[N];
ll get_par(ll x){
    if(x==par[x])return x;
    R par[x]=get_par(par[x]);
}
void mrg(ll x , ll y){
    x=get_par(x),y=get_par(y);
    if(x==y)R;
    if(sz[x]<sz[y])swap(x,y);
    sz[x]+=sz[y] , par[y]=x , special[x] |= special[y];
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m ;
    for(int i=1 ; i<=m ; i++){
        sz[i]=1;
        par[i]=i;
        special[i]=0;
    }
    vector<pair<ll,pair<ll,ll>>>v;
    for(int i=1 ; i<=n ; i++){
        cin >> k ;
        if(k==1){
            cin >> x;
            ll parent = get_par(x);
            if(!special[parent]){
                ans[i]=1;
            }
            special[parent]=1;
        }
        else{
            cin >> x >> y ;
            ll parx = get_par(x);
            ll pary = get_par(y);
            if(parx==pary)C;
            if(!special[parx] || !special[pary]){
                ans[i]=1;
            }
            mrg(x,y);
        }
    }
    ll res=0,res2=1;
    for(int i=1 ; i<=n ; i++){
        if(ans[i])res++;
    }
    for(int i=1 ; i<=res ; i++){
        res2 = (res2+res2)%Mod;
    }
    cout << res2 << " " << res << '\n';
    for(int i=1 ; i<=n ; i++){
        if(ans[i])cout << i << " ";
    }
    cout << endl ;

    return 0;
}


Comments

Submit
0 Comments
More Questions

219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC
466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem